﻿@using Shop.Entity;
@using Shop.Help;
@using Shop.Bll;
@using System.Data;
@using Shop.Help;
@using Webdiyer.WebControls.Mvc;
@{
    Layout = null;
}
@model  PagedList<DataRow>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>列表</title>
    <link href="@Url.Content("/Content/admin/css/bootstrap.min.css")" rel="stylesheet" />
    <script src="/Scripts/jquery-1.10.2.min.js"></script>
    <script src="~/Content/MvcPager/MvcPager.js"></script>
</head>
<body>
    <ol class="breadcrumb">
        <li><a href="/set/admin/center">首页></a></li>
        <li><a href="#">抢购管理></a></li>
        <li class="active">抢购图库</li>
    </ol>
    <div class="portlet-body">
        <div class="navbar-form navbar-left" role="search">
            <button type="button" class="btn btn-primary btn-sm " id="checkAll" onclick="CheckAll(this);">
                <span class="glyphicon glyphicon-check" aria-hidden="true">全选</span>
            </button>
            <button type="button" class="btn btn-primary btn-sm" onclick="Delete(null, '/groupbuy/image/delete', '/groupbuy/image/list/@(Model.CurrentPageIndex - 1 > 1 ? Model.CurrentPageIndex - 1 : 1)');">
                <span class="glyphicon glyphicon-trash" aria-hidden="true"></span>&nbsp;删除
            </button>
        </div>
        <form class="navbar-form navbar-left" id="formSearch" role="form" action="/groupbuy/image/List">
            <input type="hidden" name="PageSize" value="15" />
            <div class="form-group">
                <input type="text" class="form-control input-sm" id="SearchTitle" name="title" placeholder="请输入抢购标题" />
            </div>
            <button type="submit" class="btn btn-primary btn-sm ">
                <span class="glyphicon glyphicon-zoom-in" aria-hidden="true"></span>&nbsp;搜索
            </button>
        </form>
        <br /><br /><br />
        <div class="container-fluid">
            <div class="bs-example" id="divTable" data-example-id="simple-thumbnails">
                <div class="row">
                    @foreach (DataRow item in Model)
                    {
                        <div class="col-xs-6 col-md-3">
                            <div class="thumbnail">
                                <img src="@item["Url"]" style="height: 180px; width: 100%; ">
                                <div class="caption">
                                    <strong>@item["Title"]</strong>
                                    <div class="text-primary">
                                        排序：@item["imgSort"]
                                        <div class="pull-right">
                                            <input type="checkbox" name="subBox" value="@item["Guid"]" />
                                        </div>
                                    </div>
                                    <div class="text-primary">
                                        上传时间：@Convert.ToDateTime(item["UploadTime"]).ToString("yyyy-MM-dd HH:MM:ss")
                                    </div>
                                    <br />

                                    <a href="javascript:void(0);" data-guid="@item["Guid"]" name="upload" class="btn btn-default btn-xs" role="button" onclick="UploadImg();">重新上传</a>
                                    <a href="javascript:void(0);" class="btn btn-default btn-xs" role="button" onclick="Delete('@item["Guid"]', '/groupbuy/image/delete', '/groupbuy/image/list/@(Model.CurrentPageIndex - 1 > 1 ? Model.CurrentPageIndex - 1 : 1)');">删除</a>
                                </div>
                            </div>
                        </div>
                    }
                </div>

                <div class="col-xs-9" style="width:auto;padding-left:0px;">
                    <ul class="pagination">
                        <li>
                            <span aria-hidden="true">
                                @(Model.PageSize)条/页，@(Model.TotalPageCount)页, 共@(Model.TotalItemCount)条
                            </span>
                        </li>
                        <li>
                            <span aria-hidden="true">
                                每页
                                <select style="border-radius:4px;font-family:normal;vertical-align: text-bottom;" id="PageSize" name="PageSize" onchange="PageSizeChange();">
                                    <option value="8">8</option>
                                    <option selected="selected" value="16">16</option>
                                    <option value="24">24</option>
                                </select>
                                条
                            </span>
                        </li>
                    </ul>
                    @Ajax.Pager(Model,
                new PagerOptions
                {
                    PageIndexParameterName = "pageIndex",
                    CssClass = "pagination",
                    FirstPageText = "首页",
                    LastPageText = "尾页",
                    PrevPageText = "上一页",
                    PageIndexBoxId = "pageIndexBox",
                    GoToButtonId = "Go",
                    PageIndexOutOfRangeErrorMessage = "页码有误!",
                    NumericPagerItemCount = 8,
                    NextPageText = "下一页",
                    CurrentPagerItemTemplate = "<li class=\"active\"><a href=\"#\">{0}</a></li>",
                    DisabledPagerItemTemplate = "<li class=\"disabled\"><a>{0}</a></li>",
                    PagerItemTemplate = "<li>{0}</li>",
                    AutoHide = false,

                }, new MvcAjaxOptions
                {
                    UpdateTargetId = "divTable",
                    HttpMethod = "Post",
                    DataFormId = "formSearch",
                    EnableHistorySupport = false,
                    OnSuccess = "Success();",
                    EnablePartialLoading = true
                }
                )
                </div>
                <div class="pagination" style="width:20%;margin-top: 0px;">
                    <ul class="pagination">
                        <li>
                            <div class="input-group">
                                <span class="input-group-addon">第</span>
                                <input type="text" id="pageIndexBox" class="form-control input-sm" placeholder="" aria-describedby="sizing-addon2" oninput="InputPageIndex(this);">
                                <span class="input-group-addon">页</span>
                                <span class="input-group-btn">
                                    <button class="btn btn-primary btn-sm" id="Go" type="button">Go</button>
                                </span>
                            </div>
                        </li>
                    </ul>
                </div>

                <script type="text/javascript">
                    function Success()
                    {
                        var txt = $("#SearchTitle").val().trim();
                        if (txt.length > 0)
                        {
                            $(".title").each(function ()
                            {
                                var newTxt = $(this).html().replace(txt, txt.fontcolor("red"));
                                $(this).html(newTxt);
                            });
                        }
                        $("input[name='PageSize']").val('@ViewData["NowPageSize"]');
                        $("#PageSize").val(@ViewData["NowPageSize"]);
                    }
                </script>
            </div>
        </div>
    </div>
    @section Scripts{@{Html.RegisterMvcPagerScriptResource();}
    }
    <input type="hidden" id="hidGuid" value="" />
    <script src="/Content/layer/layer.js"></script>
    <script src="~/Content/LwsJS/List.js"></script>
    <link href="~/Content/kindeditor/themes/default/default.css" rel="stylesheet" />
    <script src="~/Content/kindeditor/kindeditor-all-min.js"></script>
    <script src="~/Content/kindeditor/lang/zh_CN.js"></script>
    <script type="text/javascript">
        function PageSizeChange()
        {
            $("input[name='PageSize']").val($("#PageSize").val());
            $("#formSearch").submit();
        }
        KindEditor.ready(function (K)
        {
            var editor = K.editor({
                allowFileManager: true,
                uploadJson: '/Content/kindeditor/asp.net/upload_json.ashx',
                fileManagerJson: '/Content/kindeditor/asp.net/file_manager_json.ashx'
            });
            K('.btn-primary').click(function ()
            {
                $("#hidGuid").val($(this).attr("data-guid"));
                editor.loadPlugin('image', function ()
                {
                    editor.plugin.imageDialog({
                        showRemote: false,
                        // imageUrl: K('#url3').val(),
                        clickFn: function (url, title, width, height, border, align)
                        {
                            $.post("/groupbuy/image/ReUpload",
                                { guid: $("#hidGuid").val(), url: url }, function (data)
                                {
                                    if (data.succ)
                                    {
                                        window.location.reload();
                                    } else
                                    {
                                        parent.layer.alert(data.msg, { title: "提示", icon: 5, time: 5000 });
                                    }
                                });
                            editor.hideDialog();
                        }
                    });
                });
            });
        });


        function InputPageIndex(obj)
        {
            var pageIndex = $(obj).val().trim();
            if (parseInt(pageIndex) > parseInt($("#TotalPageCount").val()))
            {
                $(obj).val($("#TotalPageCount").val());
            }
        }

        function GoPageIndex()
        {
            var pager = Webdiyer.MvcPagers[0];
            var pageIndex = $("#pageIndexBox").val().trim();
            var TotalPageCount = $("#TotalPageCount").val().trim();
            if (parseInt(pageIndex) > parseInt(TotalPageCount))
            {
                pageIndex = TotalPageCount;
            }
            if (pager != null)
            {
                pager.goToPage(parseInt(pageIndex));
            } else
            { alert("找不到指定的MvcPager！"); }

        }
    </script>
</body>
</html>